import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../components/login.vue"
import Home from "../components/home.vue"
import Welcome from "../components/welcome"
import Users from "../components/user/User"
import Rights from "../components/power/Rights"
import Roles from "../components/power/Roles"
Vue.use(VueRouter)


const routes=[
  { 
    path:"/",redirect:"/login"
   },
  {
    path: '/login',
    name: '登录',
    component: Login
  },
  {
    path: '/home',
    name: 'Home组件',
    component: Home,
    redirect:"/welcome",
    //登录后跳转到home页面 home页面中的el-menu添加子路由 定向跳转到/welcome页面
    children:[
     { 
      path:"/welcome",
      component:Welcome
     },
     //二级菜单点击后跳转的路由
     {
      path:"/users",
      component:Users
     },
     {
      path:"/rights",
      component:Rights
     },
     {
       path:"/roles",
       component:Roles
     }
    ]
  }
]
const router = new VueRouter({
  routes
})
  //to 将要访问的路径
  //from 代表从哪个路径跳转过来
  //next 是一个函数,表示放行
  //next() 放行 next("/login") 强制跳转
// router.beforEach((to,from,next)=>{
//   if(to.path==="/login") return next();
//   const tokenStr=window.sessionStorage.getItem("token")
//   if(!tokenStr) return next("/login")
//   next()
// })


export default router
